<template>
    <div>
        <h1>添加</h1>
        <table class="table">
             <tbody>
                <tr>
                    <td>Code</td>
                    <td>
                        <input type="text" v-model="data.code" disabled> 
                    </td>
                </tr>
                <tr>
                    <td>康复名称:</td>
                    <td>
                        <input type="text" v-model="data.kangName">
                    </td>
                </tr>
                <tr>
                    <td>状态:</td>
                    <td>
                        <input type="radio" name="kangStart" v-model="data.kangStart" :value="true">启用
                        <input type="radio" name="kangStart" v-model="data.kangStart" checked :value="false">禁用
                    </td>
                </tr>
                <tr>
                    <td>服务时长</td>
                    <td>
                        <input type="text" v-model="data.fangTime">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="button" value="添加" @click="Add">
                        <a href="Show">返回列表</a>
                    </td>
                    
                </tr>
            </tbody> 
        </table>
    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue';
import axios from 'axios';
import Moment from 'moment';
const moment=Moment();
const data=ref({
    "kangId": 0,
    "code": "",
    "kangName": "",
    "kangStart": true,
    "fangTime": 0,
    "deleId": 0
})

const Add=()=>{
/*     if(data.value.fangTime*0!=0)
{
    alert("服务时长必须是整数！")
    return;
}
if(data.value.fangTime.toString().lastIndexOf('.'))
{
    alert("服务时长必须是整数")
    return;
} */
    axios.post("https://localhost:7211/api/KangFu/Add",data.value).then(res=>{
        if(res.data>0)
    {
        alert("添加成功！");
        location.href='Show';
    }
    else{
        alert("添加失败！");
    }
    })
}
onMounted(()=>{
    setcodr();
})
//添加时自动生成
const setcodr=()=>{
    var n= Math.random().toString().substring(2,5);
    var d=Moment().format('YYYYMMDD');
    data.value.code=d+n;
}
</script>

<style scoped>

</style>